//
//  ViewController.m
//  MLSections
//
//  Created by ma c on 2017/8/10.
//  Copyright © 2017年 Mountec. All rights reserved.
//

#import "ViewController.h"
#import "MLSectionIndexView.h"

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong )UITableView *table;

@property (nonatomic,strong)NSArray<NSDictionary *> *sections;

@property (nonatomic,strong)MLSectionIndexView *indexView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.table = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.table.delegate = self;
    self.table.dataSource = self;
    self.table.tableFooterView = [UIView new];
    
    [self.view addSubview:self.table];
    [self.table registerClass:[UITableViewCell class] forCellReuseIdentifier:@"reuse"];
    
    NSArray *a = @[@"阿大名鼎鼎",@"啊啊啊啊啊啊啊",@"吖打飞机安居房倒垃圾放大；啊"];
    NSDictionary *aDict = @{@"A":a};
    
    NSArray *b = @[@"把阿达",@"波打卡机",@"帮我诶",@"八方",@"巴东发配"];
    NSDictionary *bDict = @{@"B":b};
    
    NSArray *e = @[@"额e e e e e ",@"额e e e e e ",@"额e e e e e ",@"额e e e e e ",@"额e e e e e ",@"额e e e e e ",@"额e e e e e ",@"额e e e e e "];
    NSDictionary *eDict = @{@"E":e};
    
    NSArray *f = @[@"付暗示",@"付暗示",@"付暗示",@"付暗示",@"付暗示",@"付暗示",@"付暗示",@"付暗示",@"付暗示"];
    NSDictionary *fDict = @{@"F":f};
    
    NSArray *z = @[@"钟任务",@"任务",@"钟任务",@"钟任务",@"钟任务",@"钟任务",@"钟任务",@"钟任务",@"钟任务",@"钟任务",@"钟任务"];
    NSDictionary *zDict = @{@"Z":z};
    
    self.sections = @[aDict,bDict,eDict,fDict,zDict];
    
    self.indexView = [[MLSectionIndexView alloc] initWithTable:self.table];
    [self.indexView reloadIndexs:@[@"A",@"B",@"E",@"F",@"Z"]];
    
    
    
    // Do any additional setup after loading the view, typically from a nib.
}

- (BOOL)prefersStatusBarHidden {
    return YES;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.sections.count;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    NSDictionary *sectiondata = self.sections[section];
    NSString *key = sectiondata.allKeys[0];
    return key;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSDictionary *sectiondata = self.sections[section];
    NSString *key = sectiondata.allKeys[0];
    NSArray *data = sectiondata[key];
    return data.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse"];
    NSDictionary *sectiondata = self.sections[indexPath.section];
    NSString *key = sectiondata.allKeys[0];
    NSArray *data = sectiondata[key];
    cell.textLabel.text = data[indexPath.row];
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
